#ifndef AUBORENDERER_H
#define AUBORENDERER_H

#include <qopengl.h>

#include <QMap>
#include <QVector>
#include <QMatrix4x4>

#include <qrender/renderer.h>

class QOpenGLShaderProgram;
class QOpenGLVertexArrayObject;
class QOpenGLBuffer;

class Q3dsModel;
class Q3dsMesh;

class Q3dsRenderer : public Renderer
{
public:
    Q3dsRenderer();
    ~Q3dsRenderer();

    bool reload(const QStringList &dirs, const QString &robot_type,
                const std::unordered_map<std::string, std::vector<double>> &dh);
    void setJointPositions(const std::vector<double> &joint_positions);
    void setFilter(QVector4D color);

    /// 关节位置
    std::vector<double> getJointPositions() const;

    /// 末端路点模型矩阵
    QMatrix4x4 getEndWaypointMatrix();

protected:
    void create() override;
    void render(const CameraInfo &camera) override;
    void release() override;

private:
    void generateMeshVertices(QVector<Q3dsMesh *> meshs);

private:
    std::shared_ptr<Q3dsModel> q3ds_model_{ nullptr }; ///< 3ds 模型
    std::vector<double> joint_positions_{ std::vector<double>(6, 0.) };
    QStringList dirs_{ "." };
    QString robot_type_{ "demo" };
    std::unordered_map<std::string, std::vector<double>> dh_;
    QMatrix4x4 end_waypoint_matrix_;
    QVector4D filter_color_{ 0.0, 0.0, 0.0, 0.0 };

    std::shared_ptr<QOpenGLShaderProgram> program_{ nullptr };
    std::shared_ptr<QOpenGLVertexArrayObject> vao_{ nullptr };
    std::shared_ptr<QOpenGLBuffer> vbo_{ nullptr };

    QList<QList<QPair<QVector3D, QVector<GLfloat>>>> vbo_datas_;
};

#endif // AUBORENDERER_H
